package com.xuecheng.order.controller;

import com.xuecheng.commons.model.dto.MyOrdersDto;
import com.xuecheng.commons.model.dto.OrderDto;
import com.xuecheng.commons.model.dto.PageRequest;
import com.xuecheng.commons.model.vo.ResponseResult;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.order.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;
import java.util.Date;
import java.util.Map;

/**
 * <p>
 * 订单前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
public class OrdersController {

    @Autowired
    private OrdersService  ordersService;


    // 用户下单
    @PostMapping("/orders/create/{coursePubId}")
    public ResponseResult createOrder(@PathVariable("coursePubId")Long coursePubId){
        return ordersService.createOrder(coursePubId);
    }

    // 查询支付结果
    @GetMapping("/orders/{orderNo}")
    public ResponseResult findPay(@PathVariable("orderNo") String orderNo){
        return ordersService.findPay(orderNo);
    }

    // 个人中心用户订单
    @PostMapping("/orders/my-list")
    public ResponseResult myOrder(PageRequest request, MyOrdersDto dto) throws IOException {
        return ordersService.myOrder(request,dto);
    }

    //机构的订单列表及明细 分页查询
    @PostMapping("/orders/org-list")
    public ResponseResult orderlist(PageRequest param, @RequestBody OrderDto dto,
                                    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
                                    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime){
        //调用service返回结果
        return ordersService.orderlist(param,dto,startTime,endTime);

    }


    //订单明细写入execl
    @GetMapping("/orders/order/excel")
    public ResponseResult excel(Long companyId){

        return ordersService.execl(companyId);
    }


}
